/*
 * @Author: 夏郑兴 971348024@qq.com
 * @Date: 2021-12-06 11:42:09
 * @LastEditors: 夏郑兴 971348024@qq.com
 * @LastEditTime: 2022-06-20 19:18:35
 * @FilePath: /gitee-project/Users/xzx/Desktop/A-xichen/yingxuan-git-project/pa220027-fenfa/vite.config.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { ConfigEnv, UserConfigExport } from 'vite'
import vue from '@vitejs/plugin-vue'
import { viteMockServe } from 'vite-plugin-mock'
import { resolve } from 'path'

const pathResolve = (dir: string): any => {
  return resolve(__dirname, ".", dir)
}

const alias: Record<string, string> = {
  '@': pathResolve("src")
}

// https://vitejs.dev/config/ https://cn.vitejs.dev/config
export default ({ command }: ConfigEnv): UserConfigExport => {
  const prodMock = true;
  return {
    resolve: {
      alias,
    },

    server: {
      https: false,
      port: 3010,
      host: '0.0.0.0',
      open: true, // open支持boolean/string类型，为true时打开默认浏览器，为string类型时，打开指定浏览器，具体查看官网即可
      proxy: { // 代理配置
        // '/api': 'http://192.168.14.128:8080',
        // '/api': 'http://www.zhaixiaozhi.com/backstagerpzzm/',
        // '/api': 'http://0.0.0.0:8080',
        '/api': 'http://47.93.156.6:8087',
        // '/api': 'https://fenfa-api.dokku2.yingxuan.co'
        // '/api': 'http://task-assignment.xcess.cn'
        // '/api': 'https://fenfa-vue-web.dokku2.yingxuan.co'
      },
    },
    build: {
      outDir: './dist',
      rollupOptions: {
        output: {
          manualChunks: {
            'echarts': ['echarts']
          }
        },
      }
    },
    plugins: [
      vue(),
      viteMockServe({
        mockPath: 'mock',
        localEnabled: command === 'serve',
        prodEnabled: command !== 'serve' && prodMock,
        watchFiles: true,
        injectCode: `
          import { setupProdMockServer } from '../mockProdServer';
          setupProdMockServer();
        `,
        logger: true,
      }),
    ]
  };
}
